package com.googlecode.gwtbb.client.only.widget.form.entry;

import com.google.gwt.user.client.ui.*;
import com.googlecode.gwtbb.client.shared.validation.FieldId;

import java.util.List;
import java.util.ArrayList;

/**
 * Created by IntelliJ IDEA.
 * User: user
 * Date: May 5, 2009
 */
public abstract class HtmledFormEntry extends FormEntryImpl implements HasHorizontalAlignment, HasVerticalAlignment {
	private HTML html;
	private int htmlRow = 0;
	private int htmlCol = 0;
	private int htmlRowSpan = 1;
	private int htmlColSpan = 1;
	private HorizontalAlignmentConstant htmlHorizontalAlignment = ALIGN_LEFT;
	private VerticalAlignmentConstant htmlVerticalAlignment = ALIGN_MIDDLE;
	private int entryRow = 0;
	private int entryCol = 1;
	private int entryRowSpan = 1;
	private int entryColSpan = 1;
	private HorizontalAlignmentConstant entryHorizontalAlignment = ALIGN_LEFT;
	private VerticalAlignmentConstant entryVerticalAlignment = ALIGN_MIDDLE;
	private List<WidgetCell> widgetCells;

	public HtmledFormEntry(FieldId fieldId, String defaultValue, int htmlRow, int htmlCol, String htmlText) {
		this.fieldId = fieldId;
		this.defaultValue = defaultValue;
		html = new HTML(htmlText);
		this.htmlRow = htmlRow;
		this.htmlCol = htmlCol;
		this.entryRow = htmlRow;
		this.entryCol = htmlCol + 1;
	}

	public int getEntryCol() {
		return entryCol;
	}

	public void setEntryCol(int entryCol) {
		this.entryCol = entryCol;
	}

	public int getEntryColSpan() {
		return entryColSpan;
	}

	public void setEntryColSpan(int entryColSpan) {
		this.entryColSpan = entryColSpan;
	}

	public HorizontalAlignmentConstant getEntryHorizontalAlignment() {
		return entryHorizontalAlignment;
	}

	public void setEntryHorizontalAlignment(HorizontalAlignmentConstant entryHorizontalAlignment) {
		this.entryHorizontalAlignment = entryHorizontalAlignment;
	}

	public int getEntryRow() {
		return entryRow;
	}

	public void setEntryRow(int entryRow) {
		this.entryRow = entryRow;
	}

	public int getEntryRowSpan() {
		return entryRowSpan;
	}

	public void setEntryRowSpan(int entryRowSpan) {
		this.entryRowSpan = entryRowSpan;
	}

	public VerticalAlignmentConstant getEntryVerticalAlignment() {
		return entryVerticalAlignment;
	}

	public void setEntryVerticalAlignment(VerticalAlignmentConstant entryVerticalAlignment) {
		this.entryVerticalAlignment = entryVerticalAlignment;
	}

	public HTML getHtml() {
		return html;
	}

	public void setHtml(HTML html) {
		this.html = html;
	}

	public int getHtmlCol() {
		return htmlCol;
	}

	public void setHtmlCol(int htmlCol) {
		this.htmlCol = htmlCol;
	}

	public int getHtmlColSpan() {
		return htmlColSpan;
	}

	public void setHtmlColSpan(int htmlColSpan) {
		this.htmlColSpan = htmlColSpan;
	}

	public HorizontalAlignmentConstant getHtmlHorizontalAlignment() {
		return htmlHorizontalAlignment;
	}

	public void setHtmlHorizontalAlignment(HorizontalAlignmentConstant htmlHorizontalAlignment) {
		this.htmlHorizontalAlignment = htmlHorizontalAlignment;
	}

	public int getHtmlRow() {
		return htmlRow;
	}

	public void setHtmlRow(int htmlRow) {
		this.htmlRow = htmlRow;
	}

	public int getHtmlRowSpan() {
		return htmlRowSpan;
	}

	public void setHtmlRowSpan(int htmlRowSpan) {
		this.htmlRowSpan = htmlRowSpan;
	}

	public VerticalAlignmentConstant getHtmlVerticalAlignment() {
		return htmlVerticalAlignment;
	}

	public void setHtmlVerticalAlignment(VerticalAlignmentConstant htmlVerticalAlignment) {
		this.htmlVerticalAlignment = htmlVerticalAlignment;
	}

	public List<WidgetCell> getWidgetCells() {
		if (widgetCells == null) {
			widgetCells = new ArrayList<WidgetCell>(2);
			Panel htmlCell = new VerticalPanel();
			htmlCell.add(getFailurePanel());
			htmlCell.add(html);
			widgetCells.add(new WidgetCell(htmlCell, htmlRow, htmlCol, htmlRowSpan, htmlColSpan, htmlHorizontalAlignment, htmlVerticalAlignment));
			widgetCells.add(new WidgetCell(getEntryWidget(), entryRow, entryCol, entryRowSpan, entryColSpan, entryHorizontalAlignment, entryVerticalAlignment));
		}
		return widgetCells;
	}

	public HorizontalAlignmentConstant getHorizontalAlignment() {
		throw new UnsupportedOperationException("use getHtmlHorizontalAlignment or getEntryHorizontalAlignment");
	}

	public VerticalAlignmentConstant getVerticalAlignment() {
		throw new UnsupportedOperationException("use getHtmlVerticalAlignment or getEntryVerticalAlignment");
	}

	public void setHorizontalAlignment(HorizontalAlignmentConstant align) {
		throw new UnsupportedOperationException("use setHtmlHorizontalAlignment or setEntryHorizontalAlignment");
	}

	public void setVerticalAlignment(VerticalAlignmentConstant align) {
		throw new UnsupportedOperationException("use setHtmlVerticalAlignment or setEntryVerticalAlignment");
	}
}
